const l = window.localStorage;
const s = window.sessionStorage;
import Cookies from 'js-cookie'

const f = function(p){
  return {
    get(key) {
      try {
        return JSON.parse(p.getItem(key));
      } catch (err) {
        return null;
      }
    },
    set(key, val) {
      p.setItem(key, JSON.stringify(val));
    },
    clear() {
      p.clear();
    },
    remove(key) {
      p.removeItem(key);
    }
  }
}

// cookies
const c = function(){
  return {
    get(key){
      try {
        return Cookies.get(key);
      } catch (err) {
        return null;
      }
    },
    set(key, val, date){
      if(typeof(date) === 'number'){
        date ? Cookies.set(key, val, { expires: date }) : Cookies.set(key, val);
      } else {
        console.error('请输入number类型');
      }
    },
    remove(key){
      Cookies.remove(key)
    }
  }
}

export default  {
  ls: f(l),
  ss: f(s),
  ck: c()
}

